<template>
  <div>
    <h2 class="margin-bom title">{{title}}</h2>
    <div class="table">
      <el-table :data="user" style="width: 100%" :stripe="true">
        <el-table-column type="index" label="序号" width="150"></el-table-column>
        <el-table-column label="姓名" prop="name" width="150"></el-table-column>
        <el-table-column label="性别" prop="sex" width="150"></el-table-column>
        <el-table-column label="电话" prop="tel" width="150"></el-table-column>
        <el-table-column label="时间" prop="time" width="150"></el-table-column>
        <el-table-column label="邮箱" prop="email" width="150"></el-table-column>
        <el-table-column label="备注" prop="des" width="150"></el-table-column>
        <el-table-column label="操作" fixed="right" width="180">
          <template slot-scope="scope">
            <el-button type="primary" @click="updateUser(scope.row.id)">编辑</el-button>
            <v-del :delId="scope.row.id" @del="del($event)"></v-del>
          </template>
        </el-table-column>
      </el-table>
    </div>
  </div>
</template>

<script>
import ajax from "../../common/js/ajax";
import API from "../../common/js/api";
export default {
  data() {
    return {
      title: "用户列表",
      user: []
    };
  },
  methods: {
    updateUser(id) {
      this.$router.push("/index/userCreate?id=" + id);
    },
    del(id) {
      ajax(
        API.delUser,
        "get",
        { id },
        d => {
          this.$message({
            message: "删除成功",
            type: "success"
          });
          this.init();
        },
        err => {
          this.$message({
            message: err.data.info,
            type: "warning"
          });
        }
      );
    },
    init() {
      ajax(
        API.findUser,
        "get",
        {},
        d => {
          this.user = d.data.data;
        },
        err => {
          this.$message({
            message: err.data.info,
            type: "warning"
          });
        }
      );
    }
  },
  mounted() {
    this.init();
  }
};
</script>

<style lang="stylus">
@import '../../common/css/index.styl';
.table {
  width: 80%;
  margin: 0 auto;
  min-width: 921px;
}
</style>